package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.NoticeService;
import com.igeekhome.biz.RoleManageService;
import com.igeekhome.dao.CustomerServiceMapper;
import com.igeekhome.pojo.CustomerService;
import com.igeekhome.pojo.Notice;
import com.igeekhome.pojo.RoleManage;
import com.igeekhome.pojo.WorkOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 通知表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;
    @Autowired
    private CustomerServiceMapper customerServiceMapper;
    @RequestMapping("/index_notice")
    public String index1(Model model, @RequestParam("current") Integer current, @RequestParam("size") Integer size){
        //首页4个大数据的显示
        int title1=customerServiceMapper.sessioncount(null);
        model.addAttribute("title1",title1);
        int title2=customerServiceMapper.session_processing(null);
        model.addAttribute("title2",title2);
        int title3=customerServiceMapper.cs_onlinecount(null);
        model.addAttribute("title3",title3);
        int title4=customerServiceMapper.totalMessageCount(null);
        model.addAttribute("title4",title4);

        initNoticeService(model,current,size);
        return "index";
    }
    //客服信息管理
    @RequestMapping("/noticeManage")
    public String index(Model model, @RequestParam("current") Integer current, @RequestParam("size") Integer size){

        initNoticeService(model,current,size);
        model.addAttribute("main","公告管理");
        return "notice";
    }

//删除通知列表中的某个列表，并再跳转到通知列表
    @RequestMapping("/del")
    public String del(Model model, Notice notice, @RequestParam("current") Integer current, @RequestParam("size") Integer size){

        this.noticeService.removeById(notice.getId());
        initNoticeService(model,current,size);
        model.addAttribute("main","公告管理");
        return "notice";
    }


//得到要修改的对象信息，然后跳转到修改页面
    @RequestMapping("/update")
    public String update(Model model, Notice notice, @RequestParam("current") Integer current, @RequestParam("size") Integer size){

        Notice notice1 = noticeService.getById(notice.getId());
        model.addAttribute("notice",notice1);
        model.addAttribute("current",current);
        model.addAttribute("size",size);
        model.addAttribute("main","公告编辑");
        return "updatenotice";
    }


    //修改完成,并跳转到公告管理界面
    @RequestMapping("/updateVerify")
    public String updateVerify(Notice notice, Model model,@RequestParam("current") Integer current, @RequestParam("size") Integer size){

        this.noticeService.updateById(notice);
        initNoticeService(model,current,size);
        model.addAttribute("main","公告管理");
        return "notice";
    }




    public void initNoticeService(Model model, Integer current, Integer size)
    {

        IPage<Notice> page=new Page<>(current,size);
        IPage<Notice> page1 = this.noticeService.page(page);
        List<Notice> list = page1.getRecords();
        long pagesCount = page1.getPages();

        model.addAttribute("list",list);
        model.addAttribute("pagesCount",pagesCount);
    }

}

